package com.woniu.serviceorder.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.internalcommon.dto.ApiBossOrder;
import com.woniu.internalcommon.dto.OrderInfo;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.request.DriverGrabRequest;
import com.woniu.internalcommon.request.OrderRequest;
import com.woniu.serviceorder.service.GrabService;
import com.woniu.serviceorder.service.OrderService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    OrderService orderService;

    @PostMapping("/add")

    public ResponseResult add(@RequestBody OrderRequest orderRequest, HttpServletRequest httpServletRequest){

        //打印哪个地区打车
        log.info("service-order"+orderRequest.getAddress());
        return orderService.add(orderRequest);
    }

    /**
     * 创建预约单
     * @param orderRequest
     * @return
     */
    @PostMapping("/book")
    public ResponseResult book(@RequestBody OrderRequest orderRequest , HttpServletRequest httpServletRequest){

        log.info("service-order"+orderRequest.getAddress());
        return orderService.book(orderRequest);
    }

    /**
     * 订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/detail")
    public ResponseResult<OrderInfo> detail(@RequestParam("orderId") Long orderId){
        return orderService.detail(orderId);
    }

    /**
     * 去接乘客
     * @param orderRequest
     * @return
     */
    @PostMapping("/to-pick-up-passenger")
    public ResponseResult changeStatus(@RequestBody OrderRequest orderRequest){

        return orderService.toPickPassenger(orderRequest);
    }
    /**
     * 到达乘客上车点
     * @param orderRequest
     * @return
     */
    @PostMapping("/arrived-departure")
    public ResponseResult arrivedDeparture(@RequestBody OrderRequest orderRequest){
        return orderService.arrivedDeparture(orderRequest);
    }
    /**
     * 司机接到乘客
     * @param orderRequest
     * @return
     */
    @PostMapping("/pick-up-passenger")
    public ResponseResult pickUpPassenger(@RequestBody OrderRequest orderRequest){
        return orderService.pickUpPassenger(orderRequest);
    }
    /**
     * 乘客到达目的地，行程终止
     * @param orderRequest
     * @return
     */
    @PostMapping("/passenger-getoff")
    public ResponseResult passengerGetoff(@RequestBody OrderRequest orderRequest){
        return orderService.passengerGetoff(orderRequest);
    }
    /**
     * 司机发起收款
     * @param orderRequest
     * @return
     */
    @PostMapping("/push-pay-info")
    public ResponseResult pushPayInfo(@RequestBody OrderRequest orderRequest){
        return orderService.pushPayInfo(orderRequest);
    }
    /**
     * 支付完成
     * @param orderRequest
     * @return
     */
    @PostMapping("/pay")
    public ResponseResult pay(@RequestBody OrderRequest orderRequest){

        return orderService.pay(orderRequest);
    }
    /**
     * 订单取消
     * @param orderId
     * @param identity
     * @return
     */
    @GetMapping("/cancel")
    public ResponseResult cancel(@RequestParam("orderId") Long orderId,
                                 @RequestParam("identity") String identity){

        return orderService.cancel(orderId,identity);
    }
    @GetMapping("/current")
    public ResponseResult current(String phone , String identity){
        return orderService.current(phone , identity);
    }
    @Autowired
    @Qualifier("grabByRedissonBasicService")
    private GrabService grabService;

    @PostMapping("/grab")
    public ResponseResult driverGrab(@RequestBody DriverGrabRequest driverGrabRequest){

        return grabService.grab(driverGrabRequest);

    }
    /**
     * 订单号、乘客/司机的id和手机号动态查询
     * 多条件，分页查询
     * @param apiBossOrder
     * @return
     */
    @PostMapping("/select")
    public ResponseResult<Page<OrderInfo>> select(@RequestBody ApiBossOrder apiBossOrder){
        return orderService.select(apiBossOrder);
    }
}
